package com.abhinav.spring;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.Resource;

import com.abhinav.spring.bean.HelloWorld;
import com.abhinav.spring.bean.ResourceLoaderService;

public class ResourceLoadTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		ApplicationContext ctx = new ClassPathXmlApplicationContext("SpringBeans.xml");
		Resource resource;
		
		//HelloWorld hello = (HelloWorld) ctx.getBean("helloBean");
		ResourceLoaderService resourceService = (ResourceLoaderService) ctx.getBean("resourceService");
		
		// resource = ctx.getResource("classpath:com/abhinav/spring/users.properties");
		// resource = hello.getExternalResource();
		resource = resourceService.getResource("classpath:com/abhinav/spring/users.properties");
		try {
			InputStream is = resource.getInputStream();
			BufferedReader br = new BufferedReader(new InputStreamReader(is));
			
			String line;
			while((line = br.readLine()) != null){
				System.out.println(line);
			}
			br.close();
			
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
